package com.student.Activitys.adapter;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.View;

import com.student.Activitys.R;
import com.student.Activitys.adapter.base.BaseRefreshAdapter;
import com.student.Activitys.adapter.viewholder.FooterViewHolder;
import com.student.Activitys.adapter.viewholder.PartyMsgViewHolder;
import com.student.Activitys.bean.ImageTextBean;
import com.student.Activitys.utils.Constant;

import java.util.List;

/**
 * 项目名称：智慧校园学生端
 * 类描述：团/党建信息 adapter
 * 创建人：张飞祥
 * 创建时间：2017/10/26 9:14
 * 修改人：张飞祥
 * 修改时间：2017/10/26 9:14
 * 修改备注：
 */
public class PartyMsgAdapter extends BaseRefreshAdapter {

    Context context;
    List<ImageTextBean> list;

    //上拉加载更多状态-默认为0
    private int mLoadMoreStatus = 0;

    public PartyMsgAdapter(Context context, List<ImageTextBean> list) {
        super(context, list);
        this.context = context;
        this.list = list;
    }

    @Override
    protected int getLayoutItmeResId() {
        return R.layout.item_party_msg;
    }

    @Override
    protected int getLayoutFootResId() {
        return R.layout.layout_load_footview;
    }

    @Override
    public void onBindViewHolder(RecyclerView.ViewHolder holder, int position) {
        if (holder instanceof PartyMsgViewHolder) {

            PartyMsgViewHolder viewHolder = (PartyMsgViewHolder) holder;
            //将数据保存在itemView的Tag中，以便点击时进行获取
            viewHolder.itemView.setTag(position);
            //设置标题
            viewHolder.tvPartyMsgTitle.setText(list.get(position).getTitle());

        } else if (holder instanceof FooterViewHolder) {
            FooterViewHolder footViewHolder = (FooterViewHolder) holder;
            switch (mLoadMoreStatus) {
                case Constant.PULLUP_LOAD_MORE:
                    footViewHolder.pbLoad.setVisibility(View.GONE);
                    footViewHolder.tvLoadText.setText("上拉加载更多");
                    break;
                case Constant.LOADING_MORE:
                    footViewHolder.pbLoad.setVisibility(View.VISIBLE);
                    footViewHolder.tvLoadText.setText("正加载更多...");
                    break;
                case Constant.NO_LOAD_MORE:
                    //隐藏加载更多
                    footViewHolder.pbLoad.setVisibility(View.GONE);
                    footViewHolder.tvLoadText.setText("没有更多数据可加载了...");
                    break;
            }
        }
    }

    @Override
    public void changeMoreStatus(int status) {
        mLoadMoreStatus = status;
        notifyDataSetChanged();
    }

    @Override
    public RecyclerView.ViewHolder getViewHolder(View view) {
        return new PartyMsgViewHolder(view);
    }
}
